<template>
  <div class="panel admin-panel">
    <table class="table table-hover text-center">
      <tr>
        <th>序号</th>
        <th>类别名称</th>
        <th>是否显示在首页</th>
        <th>操作</th>
      </tr>
      <category-item v-for="(category,index) in categories" :category="category" :index="index"
                     @doDel="doDel(category.id,index)"></category-item>
    </table>
  </div>

</template>

<script>
  import CategoryItem from "./CategoryItem";
  import axios from "axios"

  export default {
    props: {
      categories: Array,
      del: Function
    },
    name: "CategoryList",
    components: {
      CategoryItem
    },
    methods: {
      doDel(id, index) {
        if (confirm("确认删除？")) {
          axios.get(this.apiUrl + '/category/del/' + id).then(r => {
            if (r.data.code === "200") {
              alert("删除成功")
              this.del(index)
            }
          }).catch(error => {
            this.del(index)
          })
        }
      }
    }
  }
</script>

<style scoped>

</style>
